package org.huangrui.spark.scala.core.rdd.operate.action

import org.apache.spark.{SparkConf, SparkContext}


/**
 * @Author hr
 * @Create 2024-10-18 9:15 
 */
object Spark03_Operate_Action {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[*]").setAppName("spark")
    val sc = new SparkContext(conf)
    val rdd = sc.parallelize(List(4, 2, 3, 1), 2)
    val newRdd = rdd.map((num: Int) => num * 2)

    // TODO collect用于采集数据
    val collect = newRdd.collect()
    // TODO count获取结果数量// TODO count获取结果数量
    val count: Long = newRdd.count
    // TODO first获取结果的第一个值// TODO first获取结果的第一个值
    val first: Integer = newRdd.first
    // TODO take获取前n个结果// TODO take获取前n个结果
    val take = newRdd.take(3)

    println(s"collect: ${collect.mkString("Array(", ", ", ")")}")
    println(s"count: $count")
    println(s"first: $first")
    println(s"take: ${take.mkString("Array(", ", ", ")")}")
    sc.stop()
  }
}
